package com.ruoyi.cases.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.TreeSelect;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.JlArchivesType;
import com.ruoyi.cases.service.IJlArchivesTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 档案分类Controller
 * 
 * @author ruoyi
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/cases/type")
public class JlArchivesTypeController extends BaseController
{
    @Autowired
    private IJlArchivesTypeService jlArchivesTypeService;

    /**
     * 查询档案分类列表
     */
    @PreAuthorize("@ss.hasPermi('cases:type:list')")
    @GetMapping("/list")
    public AjaxResult list(JlArchivesType jlArchivesType)
    {
        List<JlArchivesType> list = jlArchivesTypeService.selectJlArchivesTypeList(jlArchivesType);
        return success(list);
    }

    /**
     * 导出档案分类列表
     */
    @PreAuthorize("@ss.hasPermi('cases:type:export')")
    @Log(title = "档案分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JlArchivesType jlArchivesType)
    {
        List<JlArchivesType> list = jlArchivesTypeService.selectJlArchivesTypeList(jlArchivesType);
        ExcelUtil<JlArchivesType> util = new ExcelUtil<JlArchivesType>(JlArchivesType.class);
        util.exportExcel(response, list, "档案分类数据");
    }

    /**
     * 获取档案分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('cases:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jlArchivesTypeService.selectJlArchivesTypeById(id));
    }

    /**
     * 新增档案分类
     */
    @PreAuthorize("@ss.hasPermi('cases:type:add')")
    @Log(title = "档案分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JlArchivesType jlArchivesType)
    {
        return toAjax(jlArchivesTypeService.insertJlArchivesType(jlArchivesType));
    }

    /**
     * 修改档案分类
     */
    @PreAuthorize("@ss.hasPermi('cases:type:edit')")
    @Log(title = "档案分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JlArchivesType jlArchivesType)
    {
        return toAjax(jlArchivesTypeService.updateJlArchivesType(jlArchivesType));
    }

    /**
     * 删除档案分类
     */
    @PreAuthorize("@ss.hasPermi('cases:type:remove')")
    @Log(title = "档案分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jlArchivesTypeService.deleteJlArchivesTypeByIds(ids));
    }

    /**
     * 获取档案分类下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(JlArchivesType archivesType) {
        archivesType.setStatus("0");
        List<JlArchivesType> archivesTypes = jlArchivesTypeService.selectJlArchivesTypeList(archivesType);
        List<TreeSelect> treeSelects = jlArchivesTypeService.buildTypeTreeSelect(archivesTypes);
        return AjaxResult.success(treeSelects);
    }
}
